/*
 * Copyright © 2019 by MaShibo. All Rights Reserved.
 */

package mashibo.project.etc.assistant.vo;

import android.os.Parcel;
import android.os.Parcelable;

import lombok.Data;


/**
 * 卡片基本信息
 *
 * @author MaShibo
 */
@Data
public class CardBaseSourceInfo implements Parcelable {

    public static final Creator<CardBaseSourceInfo> CREATOR = new Creator<CardBaseSourceInfo>() {
        @Override
        public CardBaseSourceInfo createFromParcel(Parcel in) {
            return new CardBaseSourceInfo(in);
        }

        @Override
        public CardBaseSourceInfo[] newArray(int size) {
            return new CardBaseSourceInfo[size];
        }
    };

    /**
     * 0015文件原始信息
     */
    private String source;

    /**
     * 发卡方标识
     */
    private String issuer;

    /**
     * 卡片类型
     */
    private String cardType;

    /**
     * 卡片版本号
     */
    private String cardVersion;

    /**
     * 卡片网络编号
     */
    private String cardNetNo;

    /**
     * 卡片编号
     */
    private String cardNo;

    /**
     * 启用时间
     */
    private String startDate;

    /**
     * 到期时间
     */
    private String endDate;

    /**
     * 车牌号
     */
    private String vehiclePlate;


    /**
     * 用户类型
     */
    private String userType;

    /**
     * 车牌颜色
     */
    private String vehicleColor;


    /**
     * 车型
     */
    private String vehicleType;


    public CardBaseSourceInfo(String source) {
        this.source = source;
        this.issuer = source.substring(0, 16);
        this.cardType = source.substring(16, 18);
        this.cardVersion = source.substring(18, 20);
        this.cardNetNo = source.substring(20, 24);
        this.userType = source.substring(24, 40);
        this.startDate = source.substring(40, 48);
        this.endDate = source.substring(48, 56);
        this.vehiclePlate = source.substring(56, 80);
        this.userType = source.substring(80, 82);
        if (cardVersion.startsWith("1")) {
            this.vehicleColor = source.substring(82, 86);
        } else {
            this.vehicleColor = source.substring(82, 84);
            this.vehicleType = source.substring(84, 86);
        }
    }

    protected CardBaseSourceInfo(Parcel in) {
        this.source = in.readString();
        this.issuer = in.readString();
        this.cardType = in.readString();
        this.cardVersion = in.readString();
        this.cardNetNo = in.readString();
        this.cardNo = in.readString();
        this.startDate = in.readString();
        this.endDate = in.readString();
        this.vehiclePlate = in.readString();
        this.userType = in.readString();
        this.vehicleColor = in.readString();
        this.vehicleType = in.readString();
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(source);
        dest.writeString(issuer);
        dest.writeString(cardType);
        dest.writeString(cardVersion);
        dest.writeString(cardNetNo);
        dest.writeString(cardNo);
        dest.writeString(startDate);
        dest.writeString(endDate);
        dest.writeString(vehiclePlate);
        dest.writeString(userType);
        dest.writeString(vehicleColor);
        dest.writeString(vehicleType);
    }
}
